package com.xgkj.diyiketang.util;

import android.content.Context;
import android.widget.Toast;

import com.xgkj.diyiketang.EatShowApp;

import static android.widget.Toast.makeText;

/**
 * Toast工具类
 *
 * @author 周作威
 * @Date: 2015年1月28日
 * @Time: 下午2:54:05
 */
public class ToastUtils {

    public static long LAST_CLOCK_TIME;
    private static Toast toast;

    public static void toastShort(String text) {
        makeText(EatShowApp.getInstance(), text, Toast.LENGTH_SHORT).show();
    }

    public static void toastShort(int resId) {
        makeText(EatShowApp.getInstance(), resId, Toast.LENGTH_SHORT).show();
    }

    public static void toastLong(String text) {
        makeText(EatShowApp.getInstance(), text, Toast.LENGTH_LONG).show();
    }

    public static void toastLong(int resId) {
        makeText(EatShowApp.getInstance(), resId, Toast.LENGTH_LONG).show();
    }

    public static void toastShort(int resId, Object... params) {
        Context context = EatShowApp.getInstance();
        if (null != params) {
            makeText(context, context.getString(resId, params), Toast.LENGTH_SHORT).show();
        } else {
            makeText(context, resId, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 单例toast
     */
    public static void toastSingle(int resId, Object... params) {
        if (toast != null)
            toast.cancel();
        toast = Toast.makeText(EatShowApp.getInstance(), ResourcesUtils.getString(resId, params), Toast.LENGTH_SHORT);
        toast.show();
    }


    /**
     * 单例toast
     */
    public static void toastSingle(String text) {
        if (toast != null)
            toast.cancel();
        toast = Toast.makeText(EatShowApp.getInstance(), text, Toast.LENGTH_SHORT);
        toast.show();
    }

    /**
     * 单例toast
     */
    public static void toastSingle(int resId) {
        if (toast != null)
            toast.cancel();
        toast = Toast.makeText(EatShowApp.getInstance(), resId, Toast.LENGTH_SHORT);
        toast.show();
    }

    // 防误点
    public synchronized static boolean isFastClick() {
        long time = System.currentTimeMillis();
        if (time - LAST_CLOCK_TIME < 500) {
            return true;
        }
        LAST_CLOCK_TIME = time;
        return false;
    }

}
